/**
 * 内置对象 Object
 */

const user = { name: "张三", age: 20 };

const keys = Object.keys(user); // 数组
console.log(keys); // [ 'name', 'age' ]

const values = Object.values(user); // 数组
console.log(values); // [ '张三', 20 ]

// object -> array
const entries = Object.entries(user); // 二维数组
console.log(entries); // [ [ 'name', '张三' ], [ 'age', 20 ] ]

const prices = {
  banana: 1,
  apple: 2,
};

// 让价格翻倍，得到新对象
console.log(Object.entries(prices));
// [ [ 'banana', 1 ], [ 'apple', 2 ] ] -> [ [ 'banana', 2 ], [ 'apple', 4 ] ]
const newEntries = Object.entries(prices).map((item) => {
  return [item[0], item[1] * 2];
});
console.log(newEntries);

// array -> object
const newPrices = Object.fromEntries(newEntries);
console.log(newPrices);
// FormData -> object -> JsonString
